﻿@{
    ViewBag.Title = "角色列表";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script type="text/javascript">
        
        var opts = {
            rows: 10,
            height: 450,
            url: "",
            para: {},
            idField: "Id",
            checkbox: false,
            columns: [
                     { field: 'Name', title: '角色名称', width: 30, sortable: true },
                    { field: 'Status', title: '状态', width: 10, sortable: true,
                        formatter: function (value, rowData, rowIndex) {
                            var format = "";
                            if (value == 1)
                                format = "启用";
                            else if (value == 2)
                                format = "禁用";
                            return format;
                        }
                    },
                    { field: 'Description', title: '说明', width: 50, sortable: true },
                    { field: 'Id', title: '操作', width: 10, sortable: false,
                        formatter: function (value, rowData, rowIndex) {
                            var doActionOptions = "<select onchange='return DoAction(this.options.selectedIndex,\"" + rowData.Id + "\")' style='width: 90px; '><option value=''>-请选择-</option>";
                            return doActionOptions+"<option>修改</option> <option>删除</option> <option>配置用户</option> </select>";
                        }
                    }
                    ]

        };

        $(function () { 
            InitList();
        });
         
        function btnAdd_Click() {
            AddRole();
        }

        function btnSearch_Click(p) {
            var name = $.trim($("#txtName").val());
            var status = $("#ddlStatus").val();
            var postUrl = "/Role/GetList/?Name=" + encodeURI(name)
                + "&Status=" + encodeURI(status);
            if (p == 1)
                thisPageNum = 1;
            InitList(postUrl);
        }
        function InitList(postUrl) {
            if (typeof (postUrl) == "undefined" || postUrl.length == 0) {
                postUrl = "/Role/GetList";
            }
            opts.url = postUrl;
            $("#DataGrid").dg(opts);
        }
        //“操作”下拉框事件
        function DoAction(i, value) {
            switch (i) {
                case 1:
                    EditRole(value); // 编辑
                    break;
                case 2:
                    DeleteRole(value); // 删除
                    break; 
                case 3:
                    openUserInRole(value);
                    break;
            }
        }

        function AddRole() {
            var url = "/Role/Edit";
            showModalMany('TaskStatus', url, '700', '500' );
            btnSearch_Click();
        }

        function EditRole(roleID) {
            var url = "/Role/Edit?roleID=" + roleID;
            showModalMany('TaskStatus', url, '700', '500');
            btnSearch_Click();
        }
        function DeleteRole(roleID) {
            if (confirm("确定要删除吗?")) {
                $.post("/Role/DeleteRole?roleID=" + roleID, function (result) {
                    if (result == 1) {
                        alert("删除成功!");
                    }
                    else {
                        alert("删除失败!" + result);
                    }
                    btnSearch_Click();
                });
            } else
                btnSearch_Click();
        }

        function openDBConfig(roleID) {
            //window.location.href = "/Role/Edit?roleID=" + roleID;
            var url = "/Role/DBConfig?roleID=" + roleID;
            showModalMany('TaskStatus', url, '700', '500');
            btnSearch_Click();
        }
        function openUserInRole(roleID) {
            //window.location.href = "/Role/Edit?roleID=" + roleID;
            var url = "/Role/UserInRole?roleID=" + roleID;
            showModalMany('TaskStatus', url, '800', '500');
            btnSearch_Click();
        }
    </script>
}
<div style="margin: 5px;">
    @{
        // 渲染输出列表
        var dataSearch = new ViewDataDictionary();
        dataSearch.Add("PanelTitle", "角色搜索");
        @Html.Partial("_SearchTitlePanel", dataSearch);
        //Html.RenderPartial("_SearchTitlePanel", dataSearch);
    }
    @Html.Partial("_SearchPanel")
</div>
<div style="margin: 5px; min-height: 300px;">
    @{
        // 渲染输出列表
        var dataGrid = new ViewDataDictionary();
        dataGrid.Add("PanelTitle", "角色列表");
        dataGrid.Add("GridID", "DataGrid");
        dataGrid.Add("ShowAddButton", true);
        dataGrid.Add("ShowDeleteButton", false);
        dataGrid.Add("ShowOtherButton", false);
        dataGrid.Add("OtherButtonID", "btnView");
        dataGrid.Add("OtherButtonValue", "查 看");
        dataGrid.Add("OtherButtonClick", "btnView_Click()");
        dataGrid.Add("ShowBackButton", false);
        dataGrid.Add("ShowCloseButton", false);
        dataGrid.Add("ShowPager", true);
        dataGrid.Add("ShowLoading", true);
        @Html.Partial("_GridPanel", dataGrid);
    }
</div>
